//
//  ActivityViewController2.m
//  UI_元旦豆瓣
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "ActivityViewController2.h"
#import "UIImageView+WebCache.h"

@interface ActivityViewController2 ()

@property (nonatomic, retain) UIScrollView *scroll;
@property (nonatomic, assign) NSInteger count1;
@property (nonatomic, assign) CGRect rect;

@end

@implementation ActivityViewController2

- (void)dealloc{
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // controllview设置
    self.view.backgroundColor = [UIColor grayColor];
    self.navigationItem.title = self.model.title;
    // 自定义高度
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], NSFontAttributeName, nil];
    // 通过文字大小 获取文本的高度
    self.rect = [self.model.content boundingRectWithSize:CGSizeMake(335, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];

    // 设置两个按钮
    UIImage *img = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/NavBar/btn_nav_back@2x.png"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction)];
    self.navigationItem.leftBarButtonItem = item;
    [item release];
    
    UIImage *img2 = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/NavBar/btn_nav_share@2x.png"];
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:[img2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(buttonAction2)];
    self.navigationItem.rightBarButtonItem = item2;
    [item2 release];
    // 创建scrollView
    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _scroll.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_scroll];
    [_scroll release];
    _scroll.contentSize = CGSizeMake(0, self.rect.size.height + 315);
    // 页面设置
    // title
    UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake(20, 30, 300, 30)];
    titleLable.backgroundColor = [UIColor clearColor];
    titleLable.text = self.model.title;
    titleLable.font = [UIFont systemFontOfSize:25];
    [_scroll addSubview:titleLable];
    // 图片
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 90, 100, 170)];
    image.backgroundColor = [UIColor redColor];
    [_scroll addSubview:image];
    [image sd_setImageWithURL:[NSURL URLWithString:self.model.image]];
    [image release];
    // 时间
    UIImageView *timeImage = [[UIImageView alloc] initWithFrame:CGRectMake(130, 90, 25, 25)];
    UIImage *time = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/ActivityDetail/icon_date_blue@2x.png"];
    timeImage.image = time;
    [_scroll addSubview:timeImage];
    [timeImage release];
    
    UILabel *timeLable = [[UILabel alloc] initWithFrame:CGRectMake(160, 90, 200, 25)];
//    timeLable.backgroundColor = [UIColor redColor];
    [_scroll addSubview:timeLable];
    NSString *str1 = [NSString stringWithFormat:@"%@", [self.model.begin_time substringWithRange:NSMakeRange(5, 11)]];
    NSString *str2 = [NSString stringWithFormat:@"%@", [self.model.end_time substringWithRange:NSMakeRange(5, 11)]];
    NSString *str = [NSString stringWithFormat:@"%@--%@", str1, str2];
    timeLable.text = str;
    timeLable.font = [UIFont systemFontOfSize:15];
    [timeLable release];
    // 举办单位
    UIImageView *nameImage = [[UIImageView alloc] initWithFrame:CGRectMake(130, 120, 25, 25)];
    UIImage *name = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/ActivityDetail/icon_sponsor_blue@2x.png"];
    nameImage.image = name;
    [_scroll addSubview:nameImage];
    [nameImage release];
    UILabel *nameLable = [[UILabel alloc] initWithFrame:CGRectMake(160, 120, 200, 25)];
    nameLable.font = [UIFont systemFontOfSize:15];
    nameLable.text = self.model.owner[@"name"];
    [_scroll addSubview:nameLable];
    [nameLable release];
    // 类型
    UIImageView *catImage = [[UIImageView alloc] initWithFrame:CGRectMake(130, 150, 25, 25)];
    UIImage *cat = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/ActivityDetail/icon_catalog_blue@2x.png"];
    catImage.image = cat;
    [_scroll addSubview:catImage];
    [catImage release];
    UILabel *catLable = [[UILabel alloc] initWithFrame:CGRectMake(160, 150, 200, 25)];
    catLable.font = [UIFont systemFontOfSize:15];
    catLable.text = self.model.category_name;
    [_scroll addSubview:catLable];
    [catLable release];
    // 地址
    UIImageView *addImage = [[UIImageView alloc] initWithFrame:CGRectMake(130, 180, 25, 25)];
    UIImage *add = [UIImage imageNamed:@"/Users/dllo/Desktop/UI/UI_元旦豆瓣/UI_元旦豆瓣/Images/ActivityDetail/icon_spot_blue@2x.png"];
    addImage.image = add;
    [_scroll addSubview:addImage];
    [addImage release];
    UILabel *addLable = [[UILabel alloc] initWithFrame:CGRectMake(160, 180, 200, 40)];
    addLable.font = [UIFont systemFontOfSize:15];
    addLable.text = self.model.address;
    addLable.numberOfLines = 2;
    [_scroll addSubview:addLable];
    [addLable release];
   
    // 活动介绍
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(20, 280, 200, 25)];
    lable.text = @"活动介绍";
    lable.font = [UIFont systemFontOfSize:25];
    [_scroll addSubview:lable];
    [lable release];
    // 详细信息
    UILabel *lable2 = [[UILabel alloc] initWithFrame:CGRectMake(20, 315, self.view.frame.size.width - 40, _rect.size.height)];
    lable2.font = [UIFont systemFontOfSize:15];
    lable2.backgroundColor = [UIColor clearColor];
    lable2.text = self.model.content;
    [_scroll addSubview:lable2];
    lable2.numberOfLines = 100;
    [lable2 release];
    NSLog(@"%@", self.model.content);
    self.count1 = 1;
    
}

- (void)buttonAction{
    [self.navigationController popToViewController:self.navigationController.viewControllers[0] animated:YES];
}

- (void)buttonAction2{
    if (_count1 == 1) {
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        [alert addAction:action2];
    [self presentViewController:alert animated:YES completion:nil];
        _count1 = 2;
    } else{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"该活动已经被收藏" preferredStyle:UIAlertControllerStyleAlert];
        
        [self presentViewController:alert animated:YES completion:nil];
         UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
         [alert addAction:action];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
